import 'package:flutter/material.dart';
import 'package:wuliu01/utils/http.dart';
import 'package:wuliu01/utils/toast.dart';
import 'package:wuliu01/utils/token.dart';

class Minepage extends StatefulWidget {
  const Minepage({super.key});

  @override
  State<Minepage> createState() => _MinepageState();
}

Map userInfo = {'avatar': '', 'name': '', 'number': 'phone'};

class _MinepageState extends State<Minepage> {
  //拿到实例
  final tokenManager = TokenManager();
  final Authorization = '';

  void getminedata() async {
    try {
      //var tokenminedata = tokenManager.getToken();
      var res = await http.get('/driver/users');
      if (res['code'] != 200) return ToastUtil.showError('获取数据失败');
      setState(() {
        userInfo = res['data'];
        print(userInfo);
      });
    } catch (e) {
      debugPrint('请求失败：$e');
      ToastUtil.showError('获取数据失败');
    }
  }

  @override
  void initState() {
    super.initState();
    getminedata();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          //背景图片
          Container(
            alignment: Alignment.topCenter,
            child: Image.asset(
              'assets/bg_page_my.jpg',
              width: MediaQuery.of(context).size.width * 1.5,
            ),
          ),
          //内容
          Container(
            alignment: Alignment.center,
            color: Colors.transparent,
            child: Column(
              children: [
                //头像+名字+编号+手机号
                Column(
                  children: [
                    const SizedBox(height: 70),
                    //头像
                    Container(
                      width: 66,
                      height: 66,
                      decoration: BoxDecoration(
                        //圆形区域
                        shape: BoxShape.circle,
                      ),
                      child: Image.network(userInfo['avatar']),
                    ),
                    const SizedBox(height: 10),
                    Text(
                      '${userInfo['name']}',
                      style: TextStyle(
                        color: Colors.white,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                    const SizedBox(height: 10),
                    Text(
                      '司机编号: ${userInfo['number']}',
                      style: TextStyle(color: Colors.white),
                    ),
                    const SizedBox(height: 5),
                    Text(
                      '手机号: ${userInfo['phone']}',
                      style: TextStyle(color: Colors.white),
                    ),
                  ],
                ),
                const SizedBox(height: 20),
                //本月任务
                Container(
                  width: 345,

                  margin: const EdgeInsets.only(
                    left: 15,
                    right: 15,
                    top: 26,
                    bottom: 15,
                  ),
                  padding: EdgeInsets.only(
                    top: 13.5,
                    bottom: 25,
                    left: 37,
                    right: 30,
                  ),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10),
                  ),
                  child: Column(
                    children: [
                      Container(
                        padding: EdgeInsets.only(bottom: 21),
                        child: Text(
                          '- 本月任务 -',
                          style: TextStyle(color: Colors.grey),
                        ),
                      ),

                      Row(
                        children: [
                          Expanded(
                            flex: 1,
                            child: Column(
                              children: [
                                Text(
                                  '18',
                                  style: TextStyle(fontWeight: FontWeight.w600),
                                ),
                                const SizedBox(height: 13),
                                Text(
                                  '任务总量',
                                  style: TextStyle(fontWeight: FontWeight.w200),
                                ),
                              ],
                            ),
                          ),
                          //
                          Expanded(
                            flex: 1,
                            child: Column(
                              children: [
                                Text(
                                  '16',
                                  style: TextStyle(fontWeight: FontWeight.w600),
                                ),
                                const SizedBox(height: 13),
                                Text(
                                  '完成任务量',
                                  style: TextStyle(fontWeight: FontWeight.w200),
                                ),
                              ],
                            ),
                          ),
                          //
                          Expanded(
                            flex: 1,
                            child: Column(
                              children: [
                                Text(
                                  '3987',
                                  style: TextStyle(fontWeight: FontWeight.w600),
                                ),
                                const SizedBox(height: 13),
                                Text(
                                  '运输里程(km)',
                                  style: TextStyle(fontWeight: FontWeight.w200),
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),

                //基本数据
                Container(
                  width: 345,
                  height: 180,
                  margin: const EdgeInsets.only(
                    left: 15,
                    right: 15,
                    top: 26,
                    bottom: 15,
                  ),
                  padding: EdgeInsets.only(
                    top: 13.5,
                    bottom: 15,
                    left: 20,
                    right: 20,
                  ),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10),
                  ),

                  child: Column(
                    children: [
                      Expanded(
                        flex: 1,
                        child: Column(
                          children: [
                            Row(
                              children: [
                                Text('车辆信息'),
                                const Spacer(),
                                Image.asset('assets/ic_btn_more.png'),
                              ],
                            ),
                            const SizedBox(height: 5),
                            Divider(
                              height: 20, // 控制分割线上下间距（非线条粗细）
                              thickness: 2, // 线条实际粗细
                              color: const Color.fromARGB(255, 229, 229, 229),
                              indent: 0, // 左侧缩进
                              endIndent: 0, // 右侧缩进
                            ),
                          ],
                        ),
                      ),
                      //
                      Expanded(
                        flex: 1,
                        child: Column(
                          children: [
                            Row(
                              children: [
                                Text('任务数据'),
                                const Spacer(),
                                Image.asset('assets/ic_btn_more.png'),
                              ],
                            ),
                            const SizedBox(height: 5),
                            Divider(
                              height: 20, // 控制分割线上下间距（非线条粗细）
                              thickness: 2, // 线条实际粗细
                              color: const Color.fromARGB(255, 229, 229, 229),
                              indent: 0, // 左侧缩进
                              endIndent: 0, // 右侧缩进
                            ),
                          ],
                        ),
                      ),
                      //
                      Expanded(
                        flex: 1,
                        child: Column(
                          children: [
                            GestureDetector(
                              onTap: () {
                                Navigator.pushNamed(context, '/detail');
                              },
                              child: Row(
                                children: [
                                  Text('系统设置'),
                                  const Spacer(),
                                  Image.asset('assets/ic_btn_more.png'),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
